#include <Math.h>
#include <Rectangle.h>

Rectangle::Rectangle (float height, float width)
{
    m_height = (checkHeightValid(height)) ? floor(height) : 0;
    m_width  = (checkWidthValid(width))? floor(width) : 0;
}

float Rectangle::getArea() const
{
    return isValid() ? round(m_height * m_width) : 0;
}

float Rectangle::getPerimeter() const
{
    return isValid() ? 2 * (m_height + m_width) : 0;
}

float Rectangle::getHeight() const
{
    return m_height;
}

float Rectangle::getWidth() const
{
    return m_width;
}

bool Rectangle::setHeight(float height)
{
    if (!checkHeightValid(floor(height)))
    {
        return false;
    }
    m_height = floor(height);
    return true;
}

bool Rectangle::setWidth(float width)
{
    if (!checkWidthValid(floor(width)))
    {
        return false;
    }
    m_width = floor(width);
    return true;
}

bool  Rectangle::isHeightValid() const
{
    return checkHeightValid(m_height);
}

bool  Rectangle::isWidthValid() const
{
    return checkWidthValid(m_width);
}

bool  Rectangle::isValid() const
{
    return (isHeightValid() && isWidthValid());
}


